import java.io.File;

import name.raynal.tool.SebOutputFile;


public class HtmMaker {

	private static final String TEMP = "C:/Windows/temp";
	
	public File makeHtm(SearchResult[] results) throws Throwable {
		SebOutputFile file = new SebOutputFile(TEMP + "/out.htm");
		file.writeLine("<style>td {font-size: 20;border-width:15px;"
				+ "border-style:solid;} .name {color: blue; font-size: 30}</style>");
		file.writeLine("<table>");
		for (int i = 0; i < results.length; i++) {
			if (i % 4 == 0) 
				file.writeLine("<tr>");
			file.writeLine("<td>");
			file.writeLine("<div class=\"name\">" + results[i].getName()
					+ "</div>" + "<br>");
			file.writeLine(results[i].getAddress() + "<br>");
			file.writeLine(results[i].getNum() + "<br>");
			file.writeLine(getFrame(results[i].getAddress()));
			file.writeLine("</td>");
			if ((i - 3) % 4 == 0) 
				file.writeLine("</tr>");
		}
		file.writeLine("</table>");
		file.close();
		return file;
	}

	private String getFrame(String address) {
		String prefix = address.split("\\d+")[0];
		String bareAddress = address.replace(prefix, "");
		return "<iframe width=\"300\" height=\"250\""
				+ "frameborder=\"0\" scrolling=\"no\" marginheight=\"0\""
				+ "marginwidth=\"0\" src=\"http://maps.google.fr/maps?" + "q="
				+ bareAddress.replaceAll("[ ]+", "+") + "&amp;ie=UTF8&amp;"
				+ "hl=fr&amp;output=embed\"></iframe>";
	}
}
